﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZX.BLL.Extend;
using ZX.Common;
using System.Data;
using System.Data.SqlClient;
namespace ZX.BLL.EHR
{
    /// <summary>
    /// 岗位
    /// </summary>
    public class  BDatPost : BaseBussnies
    {
        public BDatPost() { }
        /// <summary>
        /// 指定岗位名获得职级名称
        /// </summary>
        /// <param name="PostID"></param>
        /// <returns></returns>
        public string GetPostRankName(string PostID)
        {
            string PostRankName = "";
            try
            {
                 string s = "SELECT  p.PostID, dp.PhraseText AS PostRank FROM dbo.DatPost as p LEFT OUTER JOIN dbo.DatPhraseDetail dp ON p.PostRank = dp.PhraseID  where PostID='" + PostID + "'";
                 DataTable dt= this.GetDataBySqlComm(s);
                 if (dt.Rows.Count > 0) 
                 {
                     DataRow dr = dt.Rows[0];
                     PostRankName = dr["PostRank"].ToString();
                  
                 }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return PostRankName;
        }

        /// <summary>
        /// 批量添加岗位
        /// </summary>
        /// <param name="list"></param>
        public void BatchAddPost(IList<ZX.EHR.Library.DatPost> list)
        {
            foreach (var post in list)
            {
                this.entity = post;
                var _list = this.GetEntitysByCondition(string.Format("PositionID='{0}' and DeptID='{1}'",post.PositionID,post.DeptID));
                if (_list == null || _list.Count == 0)
                {
                    this.RunSqlCommand(string.Format("Exec sp_Sys_AddPost '{0}','{1}','{2}'", post.DeptID, post.PositionID, post.AddUser));
                }
            }
        }


        /// <summary>
        /// 设置主管岗位
        /// </summary>
        /// <param name="PostID"></param>
        public void SetManagerPost(Guid PostID)
        {
            this.RunSqlCommand(string.Format("Exec sp_Sys_SetManagerPost '{0}'", PostID));
        }
    }
}
